package com.ebo.synframework.nettybase.protoPool;

import java.util.HashMap;
import java.util.Map;


/**
 * 管理所有的Builder池
 *
 */
public class ProtoBuilderPoolManager {
	
	// key：protoname  
	private static Map<Class<?>, ProtoBuilderPool> pools = new HashMap<Class<?>, ProtoBuilderPool>();
	
	
	/**
	 * 获取指定proto的Builder
	 * @param protoClass
	 * @return Builder of the special protoClass
	 */
	public static ReusedProtoBuilder getBuilder(Class<?> protoClass){
		ProtoBuilderPool pool = pools.get(protoClass);
		if(pool==null){
			pool = new ProtoBuilderPool(protoClass);
			pools.put(protoClass, pool);
		}
		ReusedProtoBuilder builder = pool.get();
		builder.resetReleaseCounter();
		return builder;
	}
	
	public static Map<Class<?>, ProtoBuilderPool> getAllProtoBuilderPool(){
		return pools;
	}
}
